home *** CD-ROM | disk | FTP | other *** search
/ Gamers Delight 2 / Gamers Delight 2.iso / Aminet / game / role / larn.lha / action.c next >
C/C++ Source or Header  |  1995-11-19  |  14KB  |  547 lines

  1. /*
  2.     action.c
  3.  
  4.     Routines to perform the actual actions associated with various
  5.     player entered commands.
  6.  
  7.     act_remove_gems         remove gems from a throne
  8.     act_sit_throne          sit on a throne
  9.     act_up_stairs           go up stairs
  10.     act_down_stairs         go down stairs
  11.     act_drink_fountain      drink from a fountain
  12.     act_wash_fountain       wash at a fountain
  13.     act_up_shaft            up volcanic shaft
  14.     act_down_shaft          down volcanic shaft
  15.     volshaft_climbed        place player near volcanic shaft
  16.     act_desecrate_altar     desecrate an altar
  17.     act_donation_pray       pray, donating money
  18.     act_just_pray           pray, not donating money
  19.     act_prayer_heard        prayer was heard
  20.     act_ignore_altar        ignore an altar
  21.     act_open_chest          open a chest
  22.     act_open_door           open a door
  23. */
  24.  
  25. #include "header.h"
  26. #include "larndefs.h"
  27. #include "monsters.h"
  28. #include "objects.h"
  29. #include "player.h"
  30.  
  31. /*
  32.     act_remove_gems
  33.  
  34.     Remove gems from a throne.
  35.  
  36.     arg is zero if there is a gnome king associated with the throne
  37.  
  38.     Assumes that cursors() has been called previously, and that a check
  39.     has been made that the throne actually has gems.
  40. */
  41. act_remove_gems( arg )
  42. int arg ;
  43.     {
  44.     int i, k ;
  45.  
  46.     k=rnd(101);
  47.     if (k<25)
  48.         {
  49.         for (i=0; i<rnd(4); i++) 
  50.             creategem(); /* gems pop off the throne */
  51.         item[playerx][playery]=ODEADTHRONE;
  52.         know[playerx][playery]=0;
  53.         }
  54.     else if (k<40 && arg==0)
  55.         {
  56.         createmonster(GNOMEKING);
  57.         item[playerx][playery]=OTHRONE2;
  58.         know[playerx][playery]=0;
  59.         }
  60.     else 
  61.         lprcat("\nNothing happens");
  62.  
  63.     return ;
  64.     }
  65.  
  66. /*
  67.     act_sit_throne
  68.  
  69.     Sit on a throne.
  70.  
  71.     arg is zero if there is a gnome king associated with the throne
  72.  
  73.     Assumes that cursors() has been called previously.
  74. */
  75. act_sit_throne( arg )
  76. int arg ;
  77.     {
  78.     int k ;
  79.  
  80.     k=rnd(101);
  81.     if (k<30 && arg==0)
  82.         {
  83.         createmonster(GNOMEKING);
  84.         item[playerx][playery]=OTHRONE2;
  85.         know[playerx][playery]=0;
  86.         }
  87.     else if (k<35) 
  88.         { 
  89.         lprcat("\nZaaaappp!  You've been teleported!\n"); 
  90.         beep(); 
  91.         oteleport(0); 
  92.         }
  93.     else 
  94.         lprcat("\nNothing happens");
  95.  
  96.     return ;
  97.     }
  98.  
  99. /*
  100.     assumes that cursors() has been called and that a check has been made that
  101.     the user is actually standing at a set of up stairs.
  102. */
  103. act_up_stairs()
  104.     {
  105.     if (level >= 2 && level != 11)
  106.         {
  107.         newcavelevel( level - 1 )  ;
  108.         draws( 0, MAXX, 0, MAXY );
  109.         bot_linex() ;
  110.         }
  111.     else
  112.         lprcat("\nThe stairs lead to a dead end!") ;
  113.     return ;
  114.     }
  115.  
  116. /*
  117.     assumes that cursors() has been called and that a check has been made that
  118.     the user is actually standing at a set of down stairs.
  119. */
  120. act_down_stairs()
  121.     {
  122.     if (level != 0 && level != 10 && level != 13)
  123.         {
  124.         newcavelevel( level + 1 )  ;
  125.         draws( 0, MAXX, 0, MAXY );
  126.         bot_linex() ;
  127.         }
  128.     else
  129.         lprcat("\nThe stairs lead to a dead end!") ;
  130.     return ;
  131.     }
  132.  
  133. /*
  134.     Code to perform the action of drinking at a fountian.  Assumes that
  135.     cursors() has already been called, and that a check has been made that
  136.     the player is actually standing at a live fountain.
  137. */
  138. act_drink_fountain()
  139.     {
  140.     int x ;
  141.  
  142.     if (rnd(1501)<2)
  143.         {
  144.         lprcat("\nOops!  You seem to have caught the dreadful sleep!");
  145.         beep(); 
  146.         lflush();  
  147.         sleep(3);  
  148.         died(280); 
  149.         return;
  150.         }
  151.  
  152.     x = rnd(100);
  153.     if (x<7)
  154.         {
  155.         c[HALFDAM] += 200 + rnd(200);
  156.         lprcat("\nYou feel a sickness coming on");
  157.         }
  158.  
  159.     else if (x < 13)
  160.         quaffpotion(23, FALSE ); /* see invisible,but don't know the potion */
  161.  
  162.     else if (x < 45)
  163.         lprcat("\nnothing seems to have happened");
  164.  
  165.     else if (rnd(3) != 2)
  166.         fntchange(1);   /*  change char levels upward   */
  167.  
  168.     else
  169.         fntchange(-1);  /*  change char levels downward */
  170.  
  171.     if (rnd(12)<3)
  172.         {
  173.         lprcat("\nThe fountains bubbling slowly quiets");
  174.         item[playerx][playery]=ODEADFOUNTAIN; /* dead fountain */
  175.         know[playerx][playery]=0;
  176.         }
  177.     return;
  178.     }
  179.  
  180. /*
  181.     Code to perform the action of washing at a fountain.  Assumes that
  182.     cursors() has already been called and that a check has been made that
  183.     the player is actually standing at a live fountain.
  184. */
  185. act_wash_fountain()
  186.     {
  187.     int x ;
  188.  
  189.     if (rnd(100) < 11)
  190.         {
  191.         x=rnd((level<<2)+2);
  192.         lprintf("\nOh no!  The water was foul!  You suffer %d hit points!",(long)x);
  193.         lastnum=273;
  194.         losehp(x); 
  195.         bottomline();  
  196.         cursors();
  197.         }
  198.  
  199.     else if (rnd(100) < 29)
  200.         lprcat("\nYou got the dirt off!");
  201.  
  202.     else if (rnd(100) < 31)
  203.         lprcat("\nThis water seems to be hard water!  The dirt didn't come off!");
  204.  
  205.     else if (rnd(100) < 34)
  206.         createmonster(WATERLORD); /*    make water lord     */
  207.  
  208.     else
  209.         lprcat("\nnothing seems to have happened");
  210.  
  211.     return;
  212.     }
  213.  
  214. /*
  215.     Perform the act of climbing down the volcanic shaft.  Assumes
  216.     cursors() has been called and that a check has been made that
  217.     are actually at a down shaft.
  218. */
  219. act_down_shaft()
  220.     {
  221.     if (level!=0)
  222.         {
  223.         lprcat("\nThe shaft only extends 5 feet downward!");
  224.         return;
  225.         }
  226.  
  227.     if (packweight() > 45+3*(c[STRENGTH]+c[STREXTRA]))
  228.         {
  229.         lprcat("\nYou slip and fall down the shaft");
  230.         beep();
  231.         lastnum=275;
  232.         losehp(30+rnd(20));
  233.         bottomhp();
  234.         }
  235.     else if (prompt_mode)
  236.         lprcat("climb down");
  237.  
  238.     newcavelevel(MAXLEVEL);
  239.     draws(0,MAXX,0,MAXY);
  240.     bot_linex();
  241.     return;
  242.     }
  243.  
  244. /*
  245.     Perform the action of climbing up the volcanic shaft. Assumes
  246.     cursors() has been called and that a check has been made that
  247.     are actually at an up shaft.
  248.  
  249. */
  250. act_up_shaft()
  251.     {
  252.     if (level!=11) 
  253.         { 
  254.         lprcat("\nThe shaft only extends 8 feet upwards before you find a blockage!"); 
  255.         return; 
  256.         }
  257.  
  258.     if (packweight() > 45+5*(c[STRENGTH]+c[STREXTRA])) 
  259.         { 
  260.         lprcat("\nYou slip and fall down the shaft"); 
  261.         beep();
  262.         lastnum=275; 
  263.         losehp(15+rnd(20)); 
  264.         bottomhp(); 
  265.         return; 
  266.         }
  267.  
  268.     if (prompt_mode)
  269.         lprcat("climb up"); 
  270.     lflush(); 
  271.     newcavelevel(0);
  272.     volshaft_climbed( OVOLDOWN );
  273.     return;
  274.     }
  275.  
  276. /*
  277.     Perform the action of placing the player near the volcanic shaft
  278.     after it has been climbed.
  279.  
  280.     Takes one parameter:  the volcanic shaft object to be found.  If have
  281.     climbed up, search for OVOLDOWN, otherwise search for OVOLUP.
  282. */
  283. static volshaft_climbed(object)
  284. int object;
  285.     {
  286.     int i,j ;
  287.  
  288.     /* place player near the volcanic shaft */
  289.     for (i=0; i<MAXY; i++)
  290.         for (j=0; j<MAXX; j++)
  291.             if (item[j][i] == object)
  292.                 {
  293.                 playerx=j;
  294.                 playery=i;
  295.                 positionplayer();
  296.                 i=MAXY;
  297.                 break;
  298.                 }
  299.     draws(0,MAXX,0,MAXY);
  300.     bot_linex();
  301.     return ;
  302.     }
  303.  
  304. /*
  305.     Perform the actions associated with Altar desecration.
  306. */
  307. act_desecrate_altar()
  308.     {
  309.     if (rnd(100)<60)
  310.     { 
  311.     createmonster(makemonst(level+2)+8); 
  312.     c[AGGRAVATE] += 2500; 
  313.     }
  314.     else if (rnd(101)<30)
  315.     {
  316.     lprcat("\nThe altar crumbles into a pile of dust before your eyes");
  317.     forget();   /*  remember to destroy the altar   */
  318.     }
  319.     else
  320.     lprcat("\nnothing happens");
  321.     return ;
  322.     }
  323.  
  324. /*
  325.     Perform the actions associated with praying at an altar and giving a
  326.     donation.
  327. */
  328. act_donation_pray()
  329.     {
  330.     unsigned long k,temp ;
  331.  
  332.     while (1)
  333.         {
  334.         lprcat("\n\n");
  335.         cursor(1,24);
  336.         cltoeoln();
  337.         cursor(1,23);
  338.         cltoeoln();
  339.         lprcat("how much do you donate? ");
  340.         k = readnum((long)c[GOLD]);
  341.  
  342.         /* VMS has a problem with echo mode input (used in readnum()) such that the
  343.            next carriage return will shift the screen up one line.  To get around
  344.            this, if we are VMS, don't print the next carriage return.  Otherwise,
  345.            print the carriage return needed by all following messages.
  346.     Turns out that all but MS-DOS (which has 25 lines) has this problem.
  347.         */
  348. #ifdef MSDOS
  349.             lprcat("\n");
  350. #endif
  351.  
  352.         /* make giving zero gold equivalent to 'just pray'ing.  Allows player to
  353.            'just pray' in command mode, without having to add yet another command.
  354.         */
  355.         if (k == 0)
  356.             {
  357.             act_just_pray();
  358.             return;
  359.             }
  360.  
  361.         if (c[GOLD] >= k)
  362.             {
  363.             temp = c[GOLD] / 10 ;
  364.             c[GOLD] -= k;
  365.             bottomline();
  366.  
  367.             /* if player gave less than 10% of _original_ gold, make a monster
  368.             */
  369.             if (k < temp || k < rnd(50))
  370.                 {
  371.                 createmonster(makemonst(level+1));
  372.                 c[AGGRAVATE] += 200;
  373.                 return;
  374.                 }
  375.             if (rnd(101) > 50)
  376.                 {
  377.                 act_prayer_heard();
  378.                 return;
  379.                 }
  380.             if (rnd(43) == 5)
  381.                 {
  382.                 if (c[WEAR])
  383.                     lprcat("You feel your armor vibrate for a moment");
  384.                 enchantarmor();
  385.                 return;
  386.                 }
  387.             if (rnd(43) == 8)
  388.                 {
  389.                 if (c[WIELD])
  390.                     lprcat("You feel your weapon vibrate for a moment");
  391.                 enchweapon();
  392.                 return;
  393.                 }
  394.  
  395.             lprcat("Thank You.");
  396.             return ;
  397.             }
  398.  
  399.         /* Player donates more gold than they have.  Loop back around so
  400.            player can't escape the altar for free.
  401.         */
  402.         lprcat("You don't have that much!");
  403.         }
  404.     }
  405.  
  406. /*
  407.     Performs the actions associated with 'just praying' at the altar.  Called
  408.     when the user responds 'just pray' when in prompt mode, or enters 0 to
  409.     the money prompt when praying.
  410.  
  411.     Assumes cursors(), and that any leading \n have been printed (to get
  412.     around VMS echo mode problem.
  413. */
  414. act_just_pray()
  415.     {
  416.     if (rnd(100)<75) 
  417.     lprcat("nothing happens");
  418.     else if (rnd(43) == 10)
  419.     {
  420.     if (c[WEAR]) 
  421.         lprcat("You feel your armor vibrate for a moment");
  422.     enchantarmor(); 
  423.     return;
  424.     }
  425.     else if (rnd(43) == 10)
  426.     {
  427.     if (c[WIELD]) 
  428.         lprcat("You feel your weapon vibrate for a moment");
  429.     enchweapon(); 
  430.     return;
  431.     }
  432.     else 
  433.     createmonster(makemonst(level+1));
  434.     return;
  435.     }
  436.  
  437. /*
  438.     function to cast a +3 protection on the player
  439.  */
  440. static act_prayer_heard()
  441.     {
  442.     lprcat("You have been heard!");
  443.     if (c[ALTPRO]==0) 
  444.         c[MOREDEFENSES]+=3;
  445.     c[ALTPRO] += 500;   /* protection field */
  446.     bottomline();
  447.     }
  448.  
  449. /*
  450.     Performs the act of ignoring an altar.
  451.  
  452.     Assumptions:  cursors() has been called.
  453. */
  454. act_ignore_altar()
  455.     {
  456.     if (rnd(100)<30)    
  457.         {
  458.         createmonster(makemonst(level+1)); 
  459.         c[AGGRAVATE] += rnd(450); 
  460.         }
  461.     else    
  462.         lprcat("\nNothing happens");
  463.     return;
  464.     }
  465.  
  466. /*
  467.     Performs the act of opening a chest.  
  468.  
  469.     Parameters:   x,y location of the chest to open.
  470.     Assumptions:  cursors() has been called previously
  471. */
  472. act_open_chest(x,y)
  473. int x,y ;
  474.     {
  475.     int i,k;
  476.  
  477.     k=rnd(101);
  478.     if (k<40)
  479.         {
  480.         lprcat("\nThe chest explodes as you open it"); beep();
  481.         i = rnd(10);  lastnum=281;  /* in case he dies */
  482.         lprintf("\nYou suffer %d hit points damage!",(long)i);
  483.         checkloss(i);
  484.         switch(rnd(10)) /* see if he gets a curse */
  485.             {
  486.             case 1: c[ITCHING]+= rnd(1000)+100;
  487.                     lprcat("\nYou feel an irritation spread over your skin!");
  488.                     beep();
  489.                     break;
  490.  
  491.             case 2: c[CLUMSINESS]+= rnd(1600)+200;
  492.                     lprcat("\nYou begin to lose hand to eye coordination!");
  493.                     beep();
  494.                     break;
  495.  
  496.             case 3: c[HALFDAM]+= rnd(1600)+200;
  497.                     beep();
  498.                     lprcat("\nA sickness engulfs you!");    break;
  499.             };
  500.     item[x][y]=know[x][y]=0;    /* destroy the chest */
  501.         if (rnd(100)<69) creategem(); /* gems from the chest */
  502.     dropgold(rnd(110*iarg[playerx][playery]+200));
  503.         for (i=0; i<rnd(4); i++) something(iarg[playerx][playery]+2);
  504.         }
  505.     else
  506.         lprcat("\nNothing happens");
  507.     return;
  508.     }
  509.  
  510. /*
  511.     Perform the actions common to command and prompt mode when opening a
  512.     door.  Assumes cursors().
  513.  
  514.     Parameters:     the X,Y location of the door to open.
  515.     Return value:   TRUE if successful in opening the door, false if not.
  516. */
  517. act_open_door( x, y )
  518. int x ;
  519. int y ;
  520.     {
  521.     if (rnd(11)<7)
  522.         {
  523.         switch(iarg[x][y])
  524.             {
  525.             case 6: c[AGGRAVATE] += rnd(400);   break;
  526.  
  527.             case 7: lprcat("\nYou are jolted by an electric shock ");
  528.                     lastnum=274; losehp(rnd(20));  bottomline();  break;
  529.  
  530.             case 8: loselevel();  break;
  531.  
  532.             case 9: lprcat("\nYou suddenly feel weaker ");
  533.                     if (c[STRENGTH]>3) c[STRENGTH]--;
  534.                     bottomline();  break;
  535.  
  536.             default:    break;
  537.             }
  538.     return( 0 );
  539.         }
  540.     else
  541.         {
  542.         know[x][y]=0;
  543.         item[x][y]=OOPENDOOR;
  544.         return( 1 );
  545.         }
  546.     }
  547.